<form id="app-form" class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">小程序公钥</label>
        <div class="layui-input-block">
            <input type="text" name="miniapp_appid" class="layui-input" lay-verify="required" lay-reqtext="请输入小程序公钥" placeholder="请输入小程序公钥" value="{:sysconfig('wechat','miniapp_appid')}">
            <tip>填写小程序公钥。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">小程序私钥</label>
        <div class="layui-input-block">
            <input type="text" name="miniapp_appsecret" class="layui-input" lay-verify="required" lay-reqtext="请输入小程序私钥" placeholder="请输入小程序私钥" value="{:sysconfig('wechat','miniapp_appsecret')}">
            <tip>填写小程序私钥。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">小程序原始ID</label>
        <div class="layui-input-block">
            <input type="text" name="miniapp_original_id" class="layui-input" lay-verify="required" lay-reqtext="请输入小程序原始ID" placeholder="请输入小程序原始ID" value="{:sysconfig('wechat','miniapp_original_id')}">
            <tip>请输入小程序原始ID。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">小程序名称</label>
        <div class="layui-input-block">
            <input type="text" name="miniapp_name" class="layui-input" lay-reqtext="请输小程序名称" placeholder="请输小程序名称" value="{:sysconfig('wechat','miniapp_name')}">
            <tip>请输小程序名称。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">小程序码</label>
        <div class="layui-input-block">
            <img src="/admin/admin/activity/wxappQrcode?page=pages/user/index" width="100" height="100" onclick="lookImage('/admin/activity/wxappQrcode?page=pages/user/index')"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">request合法域名列表</label>
        <div class="layui-input-inline layui-input-wrap" style="width: 500px;">
            <input type="text" id="requestUrl" autocomplete="off" value="{:env('API_HOST')}" class="layui-input" disabled>
        </div>
        <div class="layui-form-mid" style="padding: 0!important;">
            <button type="button" class="layui-btn layui-btn-primary" onclick="copyText('requestUrl')">复制</button>
        </div>
    </div>

    <!--<div class="layui-form-item">
        <label class="layui-form-label">socket合法域名列表</label>
        <div class="layui-input-inline layui-input-wrap" style="width: 500px;">
            <input type="text" id="socketUrl" autocomplete="off" value="wss://{:request()->host()};" class="layui-input" disabled>
        </div>
        <div class="layui-form-mid" style="padding: 0!important;">
            <button type="button" class="layui-btn layui-btn-primary" onclick="copyText('socketUrl')">复制</button>
        </div>
    </div>-->

    <div class="layui-form-item">
        <label class="layui-form-label">uploadFile合法域名列表</label>
        <div class="layui-input-inline layui-input-wrap" style="width: 500px;">
            <input type="text" id="uploadFileUrl" autocomplete="off" value="{:env('API_HOST')}" class="layui-input" disabled>
        </div>
        <div class="layui-form-mid" style="padding: 0!important;">
            <button type="button" class="layui-btn layui-btn-primary" onclick="copyText('uploadFileUrl')">复制</button>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">downloadFile合法域名列表</label>
        <div class="layui-input-inline layui-input-wrap" style="width: 500px;">
            <input type="text" id="downloadFileUrl" autocomplete="off" value="{:env('API_HOST')}" class="layui-input" disabled>
        </div>
        <div class="layui-form-mid" style="padding: 0!important;">
            <button type="button" class="layui-btn layui-btn-primary" onclick="copyText('downloadFileUrl')">复制</button>
        </div>
    </div>

    <!--<div class="layui-form-item">
        <label class="layui-form-label">udp合法域名列表</label>
        <div class="layui-input-inline layui-input-wrap" style="width: 500px;">
            <input type="text" id="udpUrl" autocomplete="off" value="udp://{:request()->host()};" class="layui-input" disabled>
        </div>
        <div class="layui-form-mid" style="padding: 0!important;">
            <button type="button" class="layui-btn layui-btn-primary" onclick="copyText('udpUrl')">复制</button>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">业务域名列表</label>
        <div class="layui-input-inline layui-input-wrap" style="width: 500px;">
            <input type="text" id="serviceUrl" autocomplete="off" value="tcp://{:request()->host()};" class="layui-input" disabled>
        </div>
        <div class="layui-form-mid" style="padding: 0!important;">
            <button type="button" class="layui-btn layui-btn-primary" onclick="copyText('serviceUrl')">复制</button>
        </div>
    </div>-->

    <div class="hr-line"></div>
    <div class="layui-form-item text-center">
        <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="system/config/save" data-refresh="false">确认</button>
        <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
    </div>

</form>
<script>
    var upload_type = "{:sysconfig('upload','upload_type')}";

    function copyText(inputId) {
        const input = document.getElementById(inputId);
        const text = input.value;

        if (!text) {
            return;
        }

        navigator.clipboard.writeText(text)
            .then(() => {
                // 显示成功提示
                const statusDiv = document.createElement('div');
                statusDiv.textContent = '✓ 文本已复制到剪贴板！';
                statusDiv.style.position = 'fixed';
                statusDiv.style.top = '10px';
                statusDiv.style.left = '50%';
                statusDiv.style.transform = 'translateX(-50%)';
                statusDiv.style.backgroundColor = '#4bb368';
                statusDiv.style.color = 'white';
                statusDiv.style.padding = '8px 16px';
                statusDiv.style.borderRadius = '4px';
                document.body.appendChild(statusDiv);

                // 过一段时间移除提示
                setTimeout(() => {
                    document.body.removeChild(statusDiv);
                }, 2000);
            })
            .catch(err => {
                // 显示成功提示
                const statusDiv = document.createElement('div');
                statusDiv.textContent = '× 抱歉，无法复制文本。';
                statusDiv.style.position = 'fixed';
                statusDiv.style.top = '10px';
                statusDiv.style.left = '50%';
                statusDiv.style.transform = 'translateX(-50%)';
                statusDiv.style.backgroundColor = '#f56c6c';
                statusDiv.style.color = 'white';
                statusDiv.style.padding = '8px 16px';
                statusDiv.style.borderRadius = '4px';
                document.body.appendChild(statusDiv);

                // 过一段时间移除提示
                setTimeout(() => {
                    document.body.removeChild(statusDiv);
                }, 2000);
            });
    }

    function lookImage(src) {
        layer.photos({
            photos: { "data": [{"src": src}] },
            shadeClose: false,
            closeBtn: 2,
            anim: 0
        });
    }
</script>